#include "fxcc/core/graph/opengl3/ImageEffect.h"
#include "fxcc/core/graph/opengl3/Texture2DJack.h"

fxcc::graph::opengl3::ImageEffect::ImageEffect()
	:opengl3::Effect3d(ImageEffect::FragCode())
{
	m_PipeLineType.m_RasterizerType = fxcc::graph::common::RasterizerType::_NONE_;
	m_PipeLineType.m_BlendType = fxcc::graph::common::BlendType::_NONE_;
	m_PipeLineType.m_DepthStencilType = fxcc::graph::common::DepthStencilType::_DEFAULT_;

}

void fxcc::graph::opengl3::ImageEffect::Begin()
{
	Effect3d::Begin();

	m_Shader->Use();
	m_Shader->setInt("imageMap", 0);

}

void fxcc::graph::opengl3::ImageEffect::DebugTexture2DJack(const fxcc::graph::common::Texture2DJack* texture, int index, std::string name)
{
	assert(texture);

	m_Shader->Use();
	m_Shader->setInt(name.c_str(), index);
	//texture->(index);
	glBindTexture(GL_TEXTURE_2D, (unsigned int)texture->GetTextureId());
	glActiveTexture(GL_TEXTURE0 + index);

	PassData passData;
	ObjData objData;
	GetTexture2DJackBufferData(texture->m_Desc.m_MipmapData, passData, objData);
	SetPassData(passData);
	SetObjData(objData);
	
	InstQuad();
}

std::string fxcc::graph::opengl3::ImageEffect::FragCode()
{
	return R"(

out vec4 FragColor;

uniform sampler2D imageMap;

void main()
{
    vec4 color = texture(imageMap, vOut.TexCoords);
    FragColor = vec4(color.rgb, 1.0f); 

}

)";
}
